package com.service.impl;

import com.mapper.GroupImgMapper;
import com.pojo.GroupImg;
import com.pojo.GroupImgExample;
import com.service.GroupImgService;
import com.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2020/3/19 0019.
 */
@Service
public class GroupImgServiceImpl implements GroupImgService {

    @Autowired
    GroupImgMapper groupImgMapper;
    @Override
    public ServerResponse save(GroupImg groupImg) {
        Byte status =1;
        groupImg.setStatus(status);
        //执行mybatis添加方法
        int rows = groupImgMapper.insert(groupImg);
        //判断添加成功
        if (rows > 0)
            return ServerResponse.addSuccess();
        else
            return ServerResponse.addFailed();
    }

    @Override
    public ServerResponse modifyStatus(Integer id) {
        GroupImg groupImg = groupImgMapper.selectByPrimaryKey(id);
        Byte status = 0;
        groupImg.setStatus(status);
        int i = groupImgMapper.updateByPrimaryKeySelective(groupImg);
        if (i>0)
            return ServerResponse.deleteSuccess();
        return ServerResponse.deleteFailed();
    }

    @Override
    public ServerResponse modify(GroupImg groupImg) {
        int i = groupImgMapper.updateByPrimaryKeySelective(groupImg);
        if (i>0)
            return ServerResponse.updateSuccess();
        return ServerResponse.updateFailed();
    }

    @Override
    public ServerResponse getById(Integer id) {
        GroupImg GroupImg = groupImgMapper.selectByPrimaryKey(id);
        return ServerResponse.getDataSuccess(GroupImg);
    }

    @Override
    public ServerResponse getAll() {
        GroupImgExample example=new GroupImgExample();
        GroupImgExample.Criteria criteria = example.createCriteria();
        Byte status = 1;
        criteria.andStatusEqualTo(status);
        List<GroupImg> groupImgList= groupImgMapper.selectByExample(example);
        if (groupImgList!=null&&groupImgList.size()>0)
            return ServerResponse.getDataSuccess(groupImgList);
        return ServerResponse.getDataFailed("没有数据");
    }

    @Override
    public ServerResponse getByGroupId(String groupId) {
        GroupImgExample example=new GroupImgExample();
        GroupImgExample.Criteria criteria = example.createCriteria();
        Byte status = 1;
        criteria.andStatusEqualTo(status);
        criteria.andGroupIdEqualTo(Integer.valueOf(groupId));
        List<GroupImg> groupImgList = groupImgMapper.selectByExample(example);
        if (groupImgList!=null&&groupImgList.size()>0)
            return ServerResponse.getDataSuccess(groupImgList);
        return ServerResponse.getDataFailed("没有数据");
    }
}
